package com.ruoyi.web.controller.HUAWEI;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.HUAWEI.EntityRevisionDTO;
import com.ruoyi.system.domain.HUAWEI.TBtpMtlCurriculumViateTi;
import com.ruoyi.system.service.ITBtpMtlCurriculumViateTiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * EMS厂履历数据Controller
 *
 * @author ruoyi
 * @date 2023-03-08
 */
@Api(tags = "EMS厂履历数据接口api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/huawei" )
public class TBtpMtlCurriculumViateTiToController extends BaseController {

    private final ITBtpMtlCurriculumViateTiService iTBtpMtlCurriculumViateTiService;

    /**
     * 查询EMS厂履历数据列表
     */
    @ApiOperation(value = "查询EMS厂履历数据列表")
    @PreAuthorize("@ss.hasPermi('huawei:to:getList')")
    @GetMapping("/getList")
    public TableDataInfo list(TBtpMtlCurriculumViateTi tBtpMtlCurriculumViateTi)
    {
        startPage();
        LambdaQueryWrapper<TBtpMtlCurriculumViateTi> lqw = new LambdaQueryWrapper<TBtpMtlCurriculumViateTi>();

        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getProcessBy())){
            lqw.like(TBtpMtlCurriculumViateTi::getProcessBy ,tBtpMtlCurriculumViateTi.getProcessBy());
        }
        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getProcessByName())){
            lqw.like(TBtpMtlCurriculumViateTi::getProcessByName ,tBtpMtlCurriculumViateTi.getProcessByName());
        }
        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getPsn())){
            lqw.like(TBtpMtlCurriculumViateTi::getPsn ,tBtpMtlCurriculumViateTi.getPsn());
        }
        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getBarcode())){
            lqw.like(TBtpMtlCurriculumViateTi::getBarcode ,tBtpMtlCurriculumViateTi.getBarcode());
        }
        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getSn())){
            lqw.like(TBtpMtlCurriculumViateTi::getSn ,tBtpMtlCurriculumViateTi.getSn());
        }
        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getItemCode())){
            lqw.like(TBtpMtlCurriculumViateTi::getItemCode ,tBtpMtlCurriculumViateTi.getItemCode());
        }
        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getMtlVendorCode())){
            lqw.like(TBtpMtlCurriculumViateTi::getMtlVendorCode ,tBtpMtlCurriculumViateTi.getMtlVendorCode());
        }
        if (StringUtils.isNotBlank(tBtpMtlCurriculumViateTi.getMtlVendorName())){
            lqw.like(TBtpMtlCurriculumViateTi::getMtlVendorName ,tBtpMtlCurriculumViateTi.getMtlVendorName());
        }
        if (tBtpMtlCurriculumViateTi.getUploadFlag() != null){
            lqw.eq(TBtpMtlCurriculumViateTi::getUploadFlag ,tBtpMtlCurriculumViateTi.getUploadFlag());
        }
        if(tBtpMtlCurriculumViateTi.getBeginTime()!=null&&tBtpMtlCurriculumViateTi.getEndTime()!=null){
            lqw.between(TBtpMtlCurriculumViateTi::getProcessDate,tBtpMtlCurriculumViateTi.getBeginTime(),tBtpMtlCurriculumViateTi.getEndTime());
        }
        lqw.orderByDesc(TBtpMtlCurriculumViateTi::getProcessDate);
        List<TBtpMtlCurriculumViateTi> list = iTBtpMtlCurriculumViateTiService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 导出EMS厂履历数据列表
     */
    @PreAuthorize("@ss.hasPermi('huawei:ti:export')" )
    @Log(title = "EMS厂履历数据" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(TBtpMtlCurriculumViateTi tBtpMtlCurriculumViateTi) {
        LambdaQueryWrapper<TBtpMtlCurriculumViateTi> lqw = new LambdaQueryWrapper<TBtpMtlCurriculumViateTi>(tBtpMtlCurriculumViateTi);
        List<TBtpMtlCurriculumViateTi> list = iTBtpMtlCurriculumViateTiService.list(lqw);
        ExcelUtil<TBtpMtlCurriculumViateTi> util = new ExcelUtil<TBtpMtlCurriculumViateTi>(TBtpMtlCurriculumViateTi. class);
        return util.exportExcel(list, "ti" );
    }

    /**
     * 获取EMS厂履历数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('huawei:ti:query')" )
    @GetMapping(value = "/{interfaceId}" )
    public AjaxResult getInfo(@PathVariable("interfaceId" ) String interfaceId) {
        return AjaxResult.success(iTBtpMtlCurriculumViateTiService.getById(interfaceId));
    }

    /**
     * 新增EMS厂履历数据
     */
    @PreAuthorize("@ss.hasPermi('huawei:ti:add')" )
    @Log(title = "EMS厂履历数据" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TBtpMtlCurriculumViateTi tBtpMtlCurriculumViateTi) {
        return toAjax(iTBtpMtlCurriculumViateTiService.save(tBtpMtlCurriculumViateTi) ? 1 : 0);
    }

    /**
     * 修改EMS厂履历数据
     */
    @PreAuthorize("@ss.hasPermi('huawei:ti:edit')" )
    @Log(title = "EMS厂履历数据" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TBtpMtlCurriculumViateTi tBtpMtlCurriculumViateTi) {
        return toAjax(iTBtpMtlCurriculumViateTiService.updateById(tBtpMtlCurriculumViateTi) ? 1 : 0);
    }

    /**
     * 删除EMS厂履历数据
     */
    @PreAuthorize("@ss.hasPermi('huawei:ti:remove')" )
    @Log(title = "EMS厂履历数据" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{interfaceIds}" )
    public AjaxResult remove(@PathVariable String[] interfaceIds) {
        return toAjax(iTBtpMtlCurriculumViateTiService.removeByIds(Arrays.asList(interfaceIds)) ? 1 : 0);
    }

    @GetMapping("/getEntityRevision")
    @ApiOperation(value = "根据任务令获取对应软件信息MOM>HUAWEI",response = EntityRevisionDTO.class)
    public AjaxResult getEntityRevision(@RequestParam String po) {
        return iTBtpMtlCurriculumViateTiService.getEntityRevision(po);
    }


}
